import 'package:flutter/material.dart';

import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class RatingStarWidget extends StatelessWidget {
  static const Color kLightStar = Color(0xffffc900);
  static const Color kGreyStar = Color(0xffa3a5a7);
  static const double kStarSize = 16;

  final int percentage;
  final double starSize;

  RatingStarWidget(
      {Key? key,
      required this.percentage,
      this.starSize = RatingStarWidget.kStarSize})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    double rating = percentage / 20;
    int ratingFloor = rating.floor();
    int ratingCeil = rating.ceil();

    List<Widget> stars = [];
    for (int i = 0; i < ratingFloor; ++i) {
      stars.add(Icon(
        FontAwesomeIcons.solidStar,
        color: kLightStar,
        size: starSize,
      ));
    }

    if (rating % 1 != 0) {
      stars.add(Icon(
        FontAwesomeIcons.starHalfAlt,
        color: kLightStar,
        size: starSize,
      ));
    }

    for (int i = ratingCeil; i < 5; ++i) {
      stars.add(Icon(
        FontAwesomeIcons.solidStar,
        color: kGreyStar,
        size: starSize,
      ));
    }

    return Row(
      children: stars,
    );
  }
}
